package com.slkj.mapper;

import com.slkj.pojo.DocsReplyLog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.time.LocalDate;
import java.util.List;
import java.util.Set;

public interface DocsReplyLogMapper extends Mapper<DocsReplyLog> {

    //标记收藏
    @Update("UPDATE sl_doc_reply_log SET collect='1' WHERE doc_uuid=#{uuid} and receive_people=#{name}")
     void collectLogByUUIDAndName(@Param("uuid") String uuid,@Param("name") String name);

    //显示收藏
    @Select("SELECT doc_uuid FROM sl_doc_reply_log  WHERE collect='1' and receive_people=#{name}")
    List<String> findUUIDByCollectAndName(@Param("name") String name);
    //显示 本名字的 公文 UUID。 并且不能是发件人
    @Select("SELECT l.doc_uuid FROM sl_doc_reply_log l WHERE receive_people=#{name} and reply_num !=1")
    Set<String> uuidByName(@Param("name") String name);

    //标记已读
    @Update("UPDATE sl_doc_reply_log SET receive_people_status='已读' " +
            "WHERE doc_uuid=#{uuid} and receive_people=#{name}")
    void readByUUIDAndName(@Param("uuid") String uuid,@Param("name") String name);

    //显示已读比例
    @Select("SELECT (SELECT count(*) FROM sl_doc_reply_log  WHERE doc_uuid=#{uuid} and receive_people_status='已读')" +
            "/(SELECT count(*) FROM sl_doc_reply_log  WHERE doc_uuid=#{uuid} and receive_people_status='未读')")
    double readPoint(@Param("uuid") String uuid);
}
